package com.ruoyi.web.controller.mes;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.service.Impl.MesWastesettleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.mes.MesWastesettle;
import com.ruoyi.web.service.IMesWastesettleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 废料结算Controller
 * 
 * @author levicash
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/mes/wastesettle")
public class MesWastesettleController extends BaseController
{
    @Autowired
    private IMesWastesettleService mesWastesettleService;
    @Autowired
    private MesWastesettleServiceImpl mesWastesettleServiceImpl;

    /**
     * 查询废料结算列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MesWastesettle mesWastesettle)
    {
        startPage();
        List<MesWastesettle> list = mesWastesettleService.selectMesWastesettleList(mesWastesettle);
        return getDataTable(list);
    }

    /**
     * 导出废料结算列表
     */
    @Log(title = "废料结算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesWastesettle mesWastesettle)
    {
        List<MesWastesettle> list = mesWastesettleService.selectMesWastesettleList(mesWastesettle);
        ExcelUtil<MesWastesettle> util = new ExcelUtil<MesWastesettle>(MesWastesettle.class);
        util.exportExcel(response, list, "废料结算数据");
    }

    /**
     * 获取废料结算详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesWastesettleService.selectMesWastesettleById(id));
    }

    /**
     * 新增废料结算
     */
    @Log(title = "废料结算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesWastesettle mesWastesettle)
    {
        int rowId = mesWastesettleService.insertMesWastesettle(mesWastesettle);
        return AjaxResult.success(rowId);
    }

    /**
     * 修改废料结算
     */
    @Log(title = "废料结算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesWastesettle mesWastesettle)
    {
        return toAjax(mesWastesettleService.updateMesWastesettle(mesWastesettle));
    }

    /**
     * 删除废料结算
     */
    @Log(title = "废料结算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesWastesettleService.deleteMesWastesettleByIds(ids));
    }

    /**
     * 导出结算信息
     * @Date: 2024年6月21日
     * @Auth: 张恒
     */
    @PostMapping("/exportSettle")
    public AjaxResult exportSettle(@RequestBody MesWastesettle mesWastesettle){
        return mesWastesettleServiceImpl.exportSettle(mesWastesettle);
    }
}
